/** core IBRPG - we know we have YAHOO and dojo now **/

YAHOO.namespace('ibrpg.core'); 

YAHOO.ibrpg.core = function(){
    /** shorten those names! **/
    var yue = YAHOO.util.Event;
    var yud = YAHOO.util.Dom;
    var yus = YAHOO.util.Selector;
    
    
    /** private methods **/
    
    /** public stuff **/
    
    return {
        init: function() {
            console.log('init called');
            dojo.require("dojox.storage");
            // create the panel 
            YAHOO.util.Event.onDOMReady(YAHOO.ibrpg.core.createPanel);
        },
        createPanel: function(){
            YAHOO.namespace('ibrpg.panels');
            var yip = YAHOO.ibrpg.panels;
            
            var panelCont = document.createElement('div');
            panelCont.setAttribute('id','ibrpg-panelcontainer');
            
            YAHOO.util.Dom.addClass(yus.query('body')[0],'yui-skin-sam');
            yip.mainpanel = new YAHOO.widget.Panel('ibrpg-mainpanel',{
                width : "320px",
                visible : true,
                constraintoviewport : true,
                effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration: 1},
                xy:[300,0],
                modal: true
                });
            
            yip.mainpanel.setHeader("Itty Bitty RPG prototype v110 ");
            
            yip.mainpanel.setFooter("visit <a href='http://www.ittybittyrpg.com'>IttyBittyRPG.com</a> for your own RPG! "); 
            yip.mainpanel.setBody("<div id='ibrpg_mainpanel_body'></div>")
            yip.mainpanel.render(YAHOO.util.Selector.query('body')[0]); 
            
            //now create a tabview to insert in the panel:
            
            var tabView = new YAHOO.widget.TabView({orientation:"bottom"}); 
            
            tabView.addTab( new YAHOO.widget.Tab({
                label: "Intro",
                content: "<p>Welcome to Itty Bitty RPG! This is a small RPG embedded in your browser window! You create characters, fight monsters, and find fantastic treasures! Click <a id='ibrpg_trigger_chartab' href='#'>here</a> to start creating your character!</p>",
                active: true
            }));
/**
            tabView.addTab( new YAHOO.widget.Tab({
                label: 'Character',
                content: '<ul><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li></ul>'

            }));

            tabView.addTab( new YAHOO.widget.Tab({
                label: 'Shop',
                content: '<form action="#"><fieldset><legend>Lorem Ipsum</legend><label for="foo"> <input id="foo" name="foo"></label><input type="submit" value="submit"></fieldset></form>'
            }));
   **/         
            tabView.appendTo('ibrpg_mainpanel_body');
            
            //console.log(tabView.getTab(2))
            //tabView.getTab(2).set('disabled',true);
            
            yip.mainpanel.subscribe('show',YAHOO.ibrpg.core.bindPanel);
            yip.mainpanel.thetabview = tabView;
            
             
            //yip.mainpanel.cfg.setProperty('xy',[100,100]);      
            //yip.mainpanel.show();
            
            
                
        },
        bindPanel: function(){
            //get stuff from storage and show it...
            console.log('bindPanel')
            if(!yud.hasClass('ibrpg-mainpanel','bound')){
                yue.on('ibrpg_trigger_chartab', 'click', YAHOO.ibrpg.core.showCharPanel);
                yud.addClass('ibrpg-mainpanel','bound');
            }
        },
        showCharPanel: function(el){
            console.log('showCharPanel');
            console.log(YAHOO.ibrpg.panels.mainpanel)
            var theTabview = YAHOO.ibrpg.panels.mainpanel.thetabview;
            
            theTabview.addTab( new YAHOO.widget.Tab({ label: "Character", content: "<input type='text'> Character Name" }) ); 
            theTabview.set('activeIndex', 1);
        }
    
    
    }
    


}()

YAHOO.register("ibrpg", YAHOO.ibrpg.core, {version: "3.0.0", build: "110"});
